#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# ----------------------------------------------------------
# -- 
# -- 
# ****************************
# Author: lmay.Zhou
# Blog: www.lmaye.com
# Date: 
# ----------------------------------------------------------
import json
import urllib.request
import re

response = urllib.request.urlopen("http://www.vvupup.com/api/design/article/list?categoryId=2&pageSize=999");
html = response.read();
datas = json.loads(html);
data = datas["data"];

i = 1;
for dt in data:
    # print(dt);
    bid_id = str(dt["id"]);
    title = str(dt["title"]);
    tp = str(dt["categoryId"]);
    response2 = urllib.request.urlopen("http://www.vvupup.com/api/design/article/" + bid_id);
    html2 = response2.read();
    data2 = json.loads(html2);
    content = data2["content"];
    dataTime = re.findall(r"\d{4}-\d{1,2}-\d{1,2}", content);
    # print(dataTime);
    create_time = str(dataTime[0]);
    end_time = str("Null");
    try:
        end_time = str(dataTime[1]);
    except IndexError:
        pass;
    sql = "INSERT INTO biz_bids (uuid, bid_id, title, `type`, content, source_system, keyword, description, status, create_time, end_time, company, area) " \
          "VALUES  ('" + str(
        i) + "', '" + bid_id + "', '" + title + "', '" + tp + "', '', 'vanke', '', '', '1', '" + create_time + "', '" + end_time + "', '采筑电商平台', '全国');";
    print(sql);
    f = open("D:\\biz_bids.sql", "a", encoding="UTF-8");
    f.write(sql + "\n");
    f.close();
    i += 1;
